<div id="order_dashboard">
<?php
	if(!isset($this->params['isAjax']) || !$this->params['isAjax'])
	{
		$html->css("/paid_listings/css/style.css",array(),null,false);
	}
?>
<?php echo $html->link("Orders",array("action"=>"index"))?>
<?php 
	echo $form->create("Order",array('class'=>"inline_fields",'id'=>"date_form"));
	echo $form->input("start_date",array('type'=>"datePicker",'label'=>__("Generate report between :"),'div'=>false));
	echo $form->input("end_date",array('type'=>"datePicker",'label'=>false,'div'=>false));
	echo $form->end(array("label"=>__("Get Report"),'div'=>false));
?>
<span id="loading_img">
	
</span>
<div style="margin:100px">
	
</div>
<?php
	App::import('Vendor',"Reporting.GigaDataset");
	App::import('Vendor',"Reporting.GigaChart");
	
	$GigaDataSeries = new GigaDataSeries();
	//$reveueArray = Set::combine($revenue,'{n}.0.date','{n}.0.amount');
	$GigaDataSeries->add(0,$startDate);
	$endDateAdded = false;
	foreach($revenue as $revenueDay)
	{
		if($revenueDay[0]['date'] == $endDate)
		{
			$endDateAdded = true;
		}
		$GigaDataSeries->add($revenueDay[0]['amount'],$revenueDay[0]['date']);
	}
	//pr($endDate);
	//prd($GigaDataSeries);
	if(!$endDateAdded)
	{
		$GigaDataSeries->add(0,$endDate);
	}
	$GigaDataSeries->setProperty('title',__("Revenue"));
	$GigaDataSeries->setProperty('y_axis',sprintf(__("Revenue in %s"),cr("PaidListingConfig.currency_symbol")));
	$GigaDataSeries->setProperty('x_axis',__("Date"));
	$Chart = new GigaChart($GigaDataSeries);
?>
<div style="margin-right: 100px;">
<?php
	echo $Chart->render('line',array("height"=>"300px",'width'=>"95%"));
	
?>
</div>
<?php 	
	// Plans Sold Chart.
	$GigaDataSeries = new GigaDataSeries();
	//$reveueArray = Set::combine($revenue,'{n}.0.date','{n}.0.amount');
	$GigaDataSeries->add(0,$startDate);
	$endDateAdded = false;
	foreach($plansSold as $sellDay)
	{
		if($sellDay[0]['date'] == $endDate)
		{
			$endDateAdded = true;
		}
		$GigaDataSeries->add($sellDay[0]['count'],$sellDay[0]['date']);
	}
	//pr($endDate);
	//prd($GigaDataSeries);
	if(!$endDateAdded)
	{
		$GigaDataSeries->add(0,$endDate);
	}
	$GigaDataSeries->setProperty('title',__("Plan Sold"));
	$GigaDataSeries->setProperty('y_axis',__("Number of plan sold"));
	$GigaDataSeries->setProperty('x_axis',__("Date"));
	// /$GigaDataSeries->setProperty('height',"250px");
	//$GigaDataSeries->setProperty('width',"60%");
	$Chart = new GigaChart($GigaDataSeries);
?>
<div style="margin-right: 100px;">
<?php
	echo $Chart->render('line',array("height"=>"300px",'width'=>"95%"));
?>
</div>
<script>
	$(document).ready(function(){
		$('#date_form').submit(function(e){
			e.preventDefault();
			$("#loading_img").show().html('<img src="'+AJAX_LOADING_IMG+'" />');
			$.get('<?php echo $html->url(array("ajax"))?>',
				{end_date : $('#OrderEndDate').val(),start_date : $('#OrderStartDate').val()},
				function(html)
				{
					$('#order_dashboard').replaceWith(html);
				}
			)
		});
        var fixPicker = function()
        {
          var caller = $(this);
          var fn = function()
          {
            var offset = caller.offset();
            var top = offset.top;
            var left = offset.left;
            $('.ui-datepicker').css({top:.9*top,left:1.1*left});
          }
          setTimeout(fn, 500);
        }
        $('#OrderStartDate,OrderEndDate').focus(fixPicker).click(fixPicker)
	});
</script>
<style>
.ui-datepicker
{
	top:200px !important;
}
div.ui-datepicker{
 font-size:10px;
}

</style>
</div>